package com.suray.rgv60.map;

import com.suray.basic.wcs.utils.LoggerType;
import com.suray.rgv.ISeerRgvMapManage;
import com.suray.rgv.util.RgvLogger;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.Map;

public class SeerRgvMapManage implements ISeerRgvMapManage {
    private static SeerRgvMapManage seerRgvMapManage;

    //楼层对应地图名字
    private Map<Integer, String> maps;
    //地图名字对应地图路径
    private Map<String, String> mapPaths;

    private SeerRgvMapManage() {
        maps = new HashMap<>();
        mapPaths = new HashMap<>();
    }

    public synchronized static ISeerRgvMapManage getInstance() {
        if (seerRgvMapManage == null) {
            seerRgvMapManage = new SeerRgvMapManage();
        }

        return seerRgvMapManage;
    }

    /**
     * 初始化小车地图
     * @param rgvMapMap
     */
    public void initMap(Map<Integer, String> rgvMapMap) {
        if (CollectionUtils.isEmpty(rgvMapMap)) {
            RgvLogger.warn(LoggerType.INFO, rgvMapMap.size(), "初始化地图", "无效地图", this.getClass());
            return ;
        }

        for (Integer key : rgvMapMap.keySet()) {
            addMap(key, rgvMapMap.get(key));
        }
    }

    public Map<Integer, String> getMap() {
        return maps;
    }

    public Map<String, String> getMapPaths() {
        return mapPaths;
    }

    /**
     * 添加地图
     * @param layer
     * @param mapName
     */
    @Override
    public synchronized void addMap(int layer, String mapName) {
        maps.put(layer, mapName);
    }

    /**
     * 删除地图
     * @param layer
     */
    @Override
    public synchronized void deleteMap(int layer) {
        maps.remove(layer);
    }
}
